package jp.sourceforge.akjrcp.util;

import jp.sourceforge.akjrcp.commons.util.FileNameUtils;


public class SortUtils {

	public static void sortByExtension(String path[],String extensionsOrder[]){
		for (int i = 0; i < path.length-1; i++) {
			for(int j=i+1;j<path.length;j++){
				int c1=countSortNumber(path[i],extensionsOrder);
				int c2=countSortNumber(path[j],extensionsOrder);
				if(c1<c2){
					String tmp=path[i];
					path[i]=path[j];
					path[j]=tmp;
				}
			}
		}
	}
	private static int countSortNumber(String path,String extensionsOrder[]){
		int v=-1;
		for (int i = 0; i < extensionsOrder.length; i++) {
			if(FileNameUtils.getExtension(path).toLowerCase().equals(extensionsOrder[i].toLowerCase())){
				v=extensionsOrder.length-i;
				break;
			}
		}
		return v;
	}
	/*//TODO implement sort by class
	 * private static final Class[] orders=new Class[]{PSPConvertTabBuilder2.class,FFMpegConvertTabBuilder.class,PSPConvertTabBuilder.class,FLVConvertTabBuilder.class,MP3ConvertTabBuilder.class,MPEGConvertTabBuilder.class};
	
	public static void sort(IDropSomething[] somethings){
		for (int i = 0; i < somethings.length-1; i++) {
			for(int j=i+1;j<somethings.length;j++){
				int c1=countSortNumber(somethings[i]);
				int c2=countSortNumber(somethings[j]);
				if(c1<c2){
					IDropSomething tmp=somethings[i];
					somethings[i]=somethings[j];
					somethings[j]=tmp;
				}
			}
		}
	}
	private static int countSortNumber(IDropSomething something){
		int v=-1;
		for (int i = 0; i < orders.length; i++) {
			if(something.getClass().equals(orders[i])){
				v=orders.length-i;
				break;
			}
		}
		return v;
	}
	 */
}
